package cn.itcast.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SaasException  implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView mv = new ModelAndView();
//        如果捕获的是UnauthorizedException这个异常，页面要跳转到 /unauthorized.jsp
        if(ex instanceof UnauthorizedException){
            mv.setViewName("forward:/unauthorized.jsp");
        }else{
            mv.setViewName("error");
            mv.addObject("errorMsg",ex.getMessage());
        }
        return mv;
    }
}
